﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DataType.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ServerController : ControllerBase
    {
        //数据类型 
        //(1)值类型:
        //整型（int）,浮点数类型(float,double) ,布尔类型（bool）,字符型(char),精确值小数类型(decimal),日期时间 DateTime,枚举enum

        //(2)引用类型 
        //类class 接口 Interface 数组Array 委托Delegate

        //(3)指针类型 


        /// <summary>
        /// 转换 大写,小写
        /// </summary>
        /// <param name="a">参数</param>
        /// <returns></returns>
        [HttpGet("GetToUpper")]
        public IActionResult GetTransform(string a, string b)
        {
            var result1 = a.ToUpper();  //
            var result2 = b.ToLower();  //小写
            return Ok(new { result1, result2 });
        }

        /// <summary>
        /// 获取字符串的长度，截取,替换,查找某一个字符的下标
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSubstring")]
        public IActionResult GetSubstring(string phone,char value)
        {
            //Substring(第一个参数表示位置,第二个参数表示截取的长度)
            int len = phone.Length;
            string result = phone.Substring(3, 4);
            //替换 旧字符 替换 新字符
            var v = phone.Replace(result, "*****");
            var d = phone.IndexOf(value);
            return Ok(new { len, result,v, d });
        }

        /// <summary>
        /// 字符串拼接join
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetJoin")]
        public IActionResult GetJoin()
        {
            List<int> intList = new List<int>() { 1,2,3,4};
            string v = string.Join("-",intList);
            return Ok(v);
        }

        /// <summary>
        /// 去除 首尾空格 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTrim()
        {
            string str1 = "    你好";
            string str2 = "你好    ";
            string str3 = "    你好    ";
            var v1 = str1.TrimStart();
            var v2 = str2.TrimEnd();
            var v3 = str3.Trim();
            return Ok(new { v1, v2, v3 });
        }


        /// <summary>
        /// 字符串分割成子字符串数组
        /// </summary>
        /// <param name="srt"></param>
        /// <returns></returns>
        [HttpGet("GetSplit")]
        public IActionResult GetSplit(string srt)
        {
            string[] arr = srt.Split(',');
            return Ok(arr);
        }

        /// <summary>
        /// 创建一个动物类
        /// </summary>
        class Animal
        {
            public string? Name { get; set; }

            public int Age { get; set; }
        } 
        /// <summary>
        /// 接口
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetAnimalInfo")]
        public IActionResult GetAnimalInfo()
        {
            //实例化类
            Animal a = new Animal();
            //赋值
            a.Name = "dog";
            a.Age = 4;
            return Ok(a);
        }

        /// <summary>
        ///数组的 长度 升序 反转
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetArray")]
        public IActionResult GetArray()
        { 
            int[] arr = { 89, 77, 99, 60, 27,89 };
            //int n = arr.Length;          
            //Array.Sort(arr);  //对数组进行升序排序。
            //Array.Reverse(arr);  //反转数组元素的顺序。           
            var data=Array.IndexOf(arr, 89);
            var data2 = Array.LastIndexOf(arr, 60);
            return Ok(new { data,data2});
        }



        





       
        





    }
}
